package com.huabo.utils;

import java.io.Serializable;
import java.util.List;

public class PageResponse extends Response implements Serializable {

	private static final long serialVersionUID = 1L;

	private long total;

    private List<?> rows;

    public PageResponse() {
    }

    public PageResponse(Page<?> page) {
        this(CommonReturnCode.SUCCESS, page);
    }

    public PageResponse(ReturnCode returnCode, Page<?> page) {
        setCode(returnCode.code());
        setMessage(returnCode.message());
        if (page != null) {
            this.total = page.getTotal();
            this.rows = page.getData();
        }
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public List<?> getRows() {
        return rows;
    }

    public void setRows(List<?> rows) {
        this.rows = rows;
    }

    @Override
    public String toString() {
        return String.format("Response [state=%s, message=%s, total=%d, rows=%s]", getCode(), getMessage(), total, rows.toString());
    }

}
